<template>
  <div class="user_header"  >
    <!--设置图标-->
   <!-- <van-icon name="set" class="user_set" style="margin-top: 1vh" />-->
    <div class="user_avatar">
      <img :src="avatar" alt="头像" width="65" height="65" v-on:click="setMessage()" >
    </div>
    <div>{{nickName}}</div>
  </div>
</template>

<script>
import avatar_default from '@/assets/images/avatar_default.png';
import {ApiService} from "../../axios/apiService";
const getUserMessage =new ApiService('/userHome/User')
export default {
  name: 'user-header',

  props: {
    isLogin: {
      type: Boolean,
      default: false
    }
  },
mounted() {
  this.getUser()
},
  data() {
    return {
      nickName:"昵称",
      avatar: avatar_default,
      background_image: 'https://img.yzcdn.cn/vant/apple-1.jpg'
    };
  },
  methods:{
    setMessage(){
      this.$router.push({name:"user-message"})/*跳转*/
    },

    getUser(){

      getUserMessage.getViewById(getUserMessage.getCookie("userid")).then(
              res=>{
                this.nickName = res.data.name;
                if(res.data.headerUrl)this.avatar = res.data.headerUrl;
                console.log("res.data:"+res.data.headerUrl)
              }
      )
    }

  }

}
</script>

<style lang="scss" scoped>
.user_header {
  background-color: red;
  background-repeat: no-repeat;
  background-size: cover;
  height: 130px;
  text-align: center;
  color: #fff;
  padding-top: 30px;
}

.user_set {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 24px;
}
.user_avatar {
  margin-bottom: 5px;
  img {
    border: 0;
    border-radius: 50%;
  }
}
</style>
